<?php

namespace App\Admin\Controllers;

use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\JxRelation;
use \App\Models\JxList;

class JxRelationsController extends AdminController
{
    protected $title = '五行配置';
    
    protected function grid()
    {
        $grid = new Grid(new JxRelation());
	    $grid->disableExport();
	
	    $grid->column('id', 'ID');
	    $grid->column('status', '状态名称')->display(function ($value) {
            return array_column(config("site.sklb"),'name','sk')[$value];
        });
	    $grid->column('sk', '生克关系')->display(function ($value) {
            return config("site.jxgx")[$value];
        });
	    $grid->column('jx_list_id', '吉凶名称')->display(function ($value) {
            return isset($this->jxList) ? $this->jxList->name : '';
        });
	   
	    $grid->column('created_at', '创建时间')->display(function () {
		    return $this->created_at->toDatetimeString();
	    });
	
	    $grid->disableRowSelector();

        return $grid;
    }
	
	 protected function detail($id)
    {
        $show = new Show(JxRelation::findOrFail($id));
        return $show;
    }
	
    protected function form()
    {
        $form = new Form(new JxRelation());

	    $form->select('jx_list_id', '吉凶名称')->options(JxList::all()->pluck('name', 'id'))->rules('required');
	    $form->select('sk', '生克关系')->options(config("site.jxgx"))->rules('required');
	    $form->select('status', '状态名称')->options(array_column(config("site.sklb"),'name','sk'))->rules('required');
	    $form->textarea('words', '描述')->rules('required');
        return $form;
    }
}
